package baseJava;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by kai on 2015/8/9 0009.
 * instanseof 判断对象的实例是否属于一个类或接口或接口子类实例
 * isAssignOf 两个类类型一致,或者a是b的超级类或接口
 */
public class InstanseOf {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>(2);

        System.out.println(list instanceof List);//true
        System.out.println(list instanceof ArrayList);//true

        System.out.println(list.getClass().isAssignableFrom(List.class));
        System.out.println(list.getClass().isAssignableFrom(ArrayList.class));//true
        System.out.println(ArrayList.class.isAssignableFrom(List.class));
        System.out.println(List.class.isAssignableFrom(ArrayList.class));//true
    }
}
